<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel common\models\adminLog\AdminLogSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '日志管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/sys-menu') ?>
<?php $this->endBlock(); ?>
<div class="admin-log-index">

    <p>
    <button class="btn btn-danger" id="alldel" type="button">删除</button>
    </p>


    <?= GridView::widget([
	    'id' => "myform",
        'pjax'=>false,
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
        'headerRowOptions'=>['class'=>'kartik-sheet-style'],
        'filterRowOptions'=>['class'=>'filters'],
		'panel'=>[
            'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> 数据列表</h3>',
            'type'=>'default',
            'footer'=>false
        ],
        'toolbar' => ['{export}', '{toggleData}'],
        'pager'=>[
            //'options'=>['class'=>'hidden']//关闭自带分页
        ],
        'persistResize'=>false,
        'columns' => [
            [
                'class'=>'kartik\grid\CheckboxColumn',
                'headerOptions'=>['class'=>'my-table'],
            ],
			'log_id',
			[
                'attribute' => 'log_time',
                'format' => ['date', 'php:Y-m-d H:i:s']
            ],
			[
				'attribute' => 'user_id',
				'format' => 'raw',
                'value'=>function ($model) {
					$uname = $model->getUserName($model->user_id);
                    return empty($uname)?'未设置':$uname;
                },
			],
            'log_info',
            'ip_address',

            [
            'class' => 'yii\grid\ActionColumn',
            'header' => '操作',
            'template' => '{view}{delete}',
            'buttons' => [
		    		'view' => function ($url, $model, $key) {
		    			return  Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open" >查看</span>', $url, ['title' => '查看'] ) ;
		    		},
		    		
		    		'delete' => function ($url, $model, $key) {
		    			return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-trash" >删除</span>', $url, [
		    					'title' => '删除',
		    					'data'=>[
		    							'confirm'=>'你确定要删除吗？',
		    							'method'=>'post'
										]
					]) ;
		    		},		 
            	],
            ],
        ],
    ]); ?>
	    <?= \backend\components\GoLinkPager::widget([
        'pagination' => $dataProvider->pagination,
        'go' => true,
    ]); ?>
</div>
<?php $this->beginBlock('footer_scripts'); ?>
    <script>
        $(document).ready(function(){

            binddel("<?php echo Url::to(['admin-log/alldelete']);?>");

        });
    </script>
<?php $this->endBlock(); ?>
